// @(#)server.hh
// Time-stamp: <2009-02-11 15:05:16 root>
// Copyright 2008 Julian Qian
// Author: root@localhost.localdomain
// Version: $Id: server.hh,v 0.0 2008/11/19 04:41:33 root Exp $
// Keywords: 
//

#ifndef _SERVER_H
#define _SERVER_H 1

extern "C" {
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <math.h>
#include <sys/socket.h>
#include <sys/types.h>
}

#include "common.hh"

#define	SA struct sockaddr
#define SI struct sockaddr_in

#define BUFFER_LEN 200

class Server{
public:
    // static Server* theServer();
    
    Server();
    virtual ~Server();

    // UDP servo
    void servo();

    char* get_buffer();
    void set_buffer(char *ptr, int len);

    void Listen(int port);
    int Recv();
    bool Send(ip_t ip);
    bool Send();
    void Close();

    void sock_timeout(int delay);
    char *host_addr();
    int host_port();
    ip_t client_ip();
    char* client_ip_str();

    char* print_hex(char *hex, int len);
    
private:

    SI _addr; // address for server sock
    SI _cliaddr; // address for client sock
    int _sock;
    socklen_t _slen;
    char _buffer[PROTO_LENG_TMP]; // buffer to receive client data
    int _blen;
    
    // debug
    char tmpbuf[BUFFER_LEN];

    // static Server* _theServer();
};


#endif /* _SERVER_H */

